package handler

import (
	"github.com/gin-gonic/gin"
	"github.com/lab-online/internal/user/constant"
	"github.com/lab-online/internal/user/entity"
	mw "github.com/lab-online/pkg/middleware"
	"github.com/lab-online/pkg/resp"
)

type DeleteUserReqParams struct {
	Username string `uri:"id" binding:"required" example:"20240126"` // 学号或者工号
}

var DeleteUserValidator = mw.NewValidator(func() *mw.ValidatorOptions {
	return &mw.ValidatorOptions{
		Params: &DeleteUserReqParams{},
	}
})

type DeleteUserRespBody struct {
	resp.BaseRespBody
}

type DeleteUserFailedRespBody struct {
	resp.BaseRespBody
	Err string `json:"err"  binding:"required" example:"错误信息"`
}

// DeleteUser
//
//	@Summary				删除用户
//	@Description.markdown	DeleteUser
//	@Tags					user
//	@Accept					json
//	@Produce				json
//	@Param					Authorization	header		string	true	"`Admin`"
//	@Param					id				path		string	true	"学号或者工号"
//	@Success				200				{object}	DeleteUserRespBody
//	@Failure				400				{object}	DeleteUserFailedRespBody
//	@Security				bearer
//	@x-apifox-status		"testing"
//	@Router					/v1/users/:id [delete]
func (h *Handler) DeleteUser(c *gin.Context) {
	params := c.MustGet(mw.KeyParams).(*DeleteUserReqParams)

	userEntity := entity.NewUserEntity(entity.WithUsername(params.Username))

	if err := h.domain.DeleteUser(userEntity); err != nil {
		resp.ErrorHandler(c, err)
	} else {
		resp.Success[any](c, constant.CodeSuccessDelete)
	}
}
